require "#{RAILS_ROOT}/app/classes/irt/irt"
require "#{RAILS_ROOT}/app/classes/cat/cat_item"
require "#{RAILS_ROOT}/app/classes/cat/cat_examinee"
require "#{RAILS_ROOT}/app/classes/cat/cat_exam"
require "#{RAILS_ROOT}/app/classes/irt/irt_algorithm"

#* ability_estimator.rb
#* Copyright (C) 2010  Embian Inc.
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with This program.  If not, see <http://www.gnu.org/licenses/>.
#  
#* Estimates ability of examinees with IRT components
#* Author: KyoungMo Yang(E-mail : mo@embian.com)
#* Modified: 2010-12-01
#* References: UserProfile, IRT, CATItem, CATExaminee, CATExam, IRTAlgorithm
class AbilityEstimator
  attr_accessor :profile
  
  #* Functionailities
  # * Constructs an instance of AbilityEstimator class
  #* Parameters 
  # * [profile] : an instance of UserProfile class
  #* Return
  # * [instance] : an instance of AbilityEstimator class
  #* Note
  # * N/A
  def initialize(profile)
    @profile = profile
  end
  
  #* Functionailities
  # * Estimates ability of examinee
  #* Parameters 
  # * N/A
  #* Return
  # * [theta] : ability of examinee
  #* Note
  # * N/A
  def estimates
    if @profile.exam.examinee && @profile.exam.number_of_items > 0
      @profile.prev_theta = @profile.theta
      irt = IRT.new(@profile.exam, @profile.cat_model)
      irt.load_estimated_item_params
      irt.estimates_examinee_theta
      irt.release
    end
    
    return @profile.theta
  end
end